# 思路：转换成两个树是否互为镜像
# 这样每次递归的为左树的左子树和右树的右子树是否互为镜像，
# 左树的右子树和右树的左子树是否互为镜像
from tools.treeNode import Tree


def isSymmetric(root):
    return check(root, root)


def check(tree1, tree2):
    if (not tree1) and (not tree2):
        return True
    if (not tree1) or (not tree2):
        return False
    return tree1.val == tree2.val and check(tree1.left, tree2.right) and check(tree1.right, tree2.left)


root = Tree(1)
root.left = Tree(2)
root.right = Tree(2)
root.left.left = Tree(3)
root.left.right = Tree(4)
# root.right.left = Tree(4)
root.right.right = Tree(3)
print(isSymmetric(root))
